package com.gistone.commis.api.restController;

import com.gistone.commis.constant.Status;
import com.gistone.commis.dto.*;
import com.gistone.commis.entity.*;
import com.gistone.commis.mapper.*;
import com.gistone.commis.query.QueryPerson;
import com.gistone.commis.util.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.method.P;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.*;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

@RestController("apiPersonController")
@RequestMapping("api/person")
public class PersonController {

    private static final Logger logger = LoggerFactory.getLogger(PersonController.class);


    @Autowired
    private PersonMapper personMapper;

    @Autowired
    private PersonCcMapper personCcMapper;
    @Autowired
    private PositionTypeMapper positionTypeMapper;


    @Autowired
    private PersonLogMapper personLogMapper;

    @Autowired
    private CommunityMapper communityMapper;

    @Autowired
    private DepartMapper departMapper;


    @RequestMapping(method = RequestMethod.POST, value = "/import")
    public Result importData(MultipartFile file, HttpServletResponse response) {

        try {
            String filename = file.getOriginalFilename();
            System.out.println(filename);
            if (filename.isEmpty()) {
                return new Result(Status.FILE_EMPTY, "文件为空", "");
            }
            Workbook workbook = null;
            if (filename.endsWith(".xls")) {
                //excel 2003 .xls
                workbook = new HSSFWorkbook(file.getInputStream());
            } else if (filename.endsWith(".xlsx")) {
                //excel 2007 .xlsx
                workbook = new XSSFWorkbook(file.getInputStream());
            } else {
                return new Result(Status.FILE_FOMORT_ERROR, "文件格式不正确", "");
            }
            //从第一工作表开始
            for (int numSheet = 0; numSheet < workbook.getNumberOfSheets(); numSheet++) {
                Sheet sheet = workbook.getSheetAt(numSheet);
                if (sheet == null) {
                    continue;
                }
                // Read the Row 从第二行开始读
                for (int rowNum = 1; rowNum <= sheet.getLastRowNum(); rowNum++) {
                    Row row = sheet.getRow(rowNum);
                    if (row != null) {
                        Person person = new Person();
                        person.setPersonId(Integer.valueOf(row.getCell(0).getStringCellValue()));
                        if (0 == row.getCell(1).getCellType()) {
                            person.setNumber((int) row.getCell(1).getNumericCellValue());
                        } else {
                            person.setNumber(Integer.valueOf(row.getCell(1).getStringCellValue()));
                        }
                        person.setPersonName(row.getCell(2).getStringCellValue());
                        if (0 == row.getCell(3).getCellType()) {
                            person.setPension(row.getCell(3).getNumericCellValue());
                        } else {
                            person.setPension(Double.valueOf(row.getCell(3).getStringCellValue()));
                        }
                        if (0 == row.getCell(4).getCellType()) {
                            person.setMedicare(row.getCell(4).getNumericCellValue());
                        } else {
                            person.setMedicare(Double.valueOf(row.getCell(4).getStringCellValue()));
                        }

                        if (0 == row.getCell(5).getCellType()) {
                            person.setUnemployment(row.getCell(5).getNumericCellValue());
                        } else {
                            person.setUnemployment(Double.valueOf(row.getCell(5).getStringCellValue()));
                        }
                        if (0 == row.getCell(6).getCellType()) {
                            person.setProvidentFund(row.getCell(6).getNumericCellValue());
                        } else {
                            person.setProvidentFund(Double.valueOf(row.getCell(6).getStringCellValue()));
                        }
//                        if (0 == row.getCell(6).getCellType()) {
//                            person.setIncomeTax(row.getCell(6).getNumericCellValue());
//                        } else {
//                            person.setIncomeTax(Double.valueOf(row.getCell(6).getStringCellValue()));
//                        }

//                        person.setBackPay(row.getCell(6).getNumericCellValue());
//                        person.setSupPf(row.getCell(7).getNumericCellValue());
//                        person.setSupI(row.getCell(8).getNumericCellValue());

                        personMapper.updateByPrimaryKeySelective(person);


                    }
                }


            }
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(Status.ERROR, "发生错误，请检查上传文件后重新上传", "");//
        }
        return new Result(null);//保存成功


    }

    @RequestMapping(method = RequestMethod.GET, value = "/export")
    public void export(HttpServletResponse response) throws IOException {
        String fileName = "人员信息" + DateUtil.DateToStr2(new Date()) + ".xls";
        String sheetName = "人员信息";//sheet名
        String[] title = new String[]{"人员Id（不可更改）", "序号", "姓名", "养老", "医疗", "失业", "公积金"};//标题


        QueryPerson qp = new QueryPerson();
        qp.setIsDelete(0);
        qp.setEnlistType("社招");


        List<Person> list = personMapper.selectSelective(qp);//内容社招list


        String[][] values = new String[list.size()][];
        for (int i = 0; i < list.size(); i++) {
            values[i] = new String[title.length];
            //将对象内容转换成string
            Person person = list.get(i);
            values[i][0] = person.getPersonId() + "";
            values[i][1] = person.getNumber() + "";
            values[i][2] = person.getPersonName() + "";
            values[i][3] = person.getPension() + "";
            values[i][4] = person.getMedicare() + "";
            values[i][5] = person.getUnemployment() + "";
            values[i][6] = person.getProvidentFund() + "";
//            values[i][6] = person.getIncomeTax()+"";
//            values[i][6] = person.getBackPay()+"";
//            values[i][7] = person.getSupPf()+"";
//            values[i][8] = person.getSupI()+"";

        }

        HSSFWorkbook wb = ExcelUtil.getHSSFWorkbook(sheetName, title, values, null);

        //将文件存到指定位置
        try {
            ResponseHeaderUtil.setResponseHeader(response, fileName);
            OutputStream os = response.getOutputStream();
            wb.write(os);
            os.flush();
            os.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
//        return JResponse.success("ok");
//
//        InputStream inputStream = new BufferedInputStream(new FileInputStream(file));
//        FileCopyUtils.copy(inputStream, response.getOutputStream());
    }

    @Transactional
    @RequestMapping(method = RequestMethod.GET, value = "/addwage")
    public Result addwage(Integer flag) {
        QueryPerson p = new QueryPerson();
        p.setIsDelete(0);
        List<Person> personList = personMapper.selectSelective(p);
        Calendar now = Calendar.getInstance();
        int nowYear = now.get(Calendar.YEAR);
        int nowMonth = now.get(Calendar.MONTH) + 1;


        if (nowMonth != 1 && null == flag) {
            return new Result(Status.CONFIRM, "只有一月份才能更新职务年限补贴", "");
        }

        for (Person person : personList) {
            logger.info("----------------");
            Calendar w = Calendar.getInstance();
            System.out.println("date---" + p.getSWorkDate());
            w.setTime(person.getSWorkDate());
            int wYear = w.get(Calendar.YEAR);
            int wMonth = w.get(Calendar.MONTH) + 1;
            if (wYear == nowYear - 1) {
                if (wMonth >= 4 && wMonth <= 12) {//4-12月不增加
                    logger.info("--不增加");
                    continue;//不修改数据

                }

            }
            logger.info("--更改增加");
            person.setZwnxbt(person.getZwnxbt() + 50);
            personMapper.updateByPrimaryKeySelective(person);
            logger.info("----------------");

        }


        return new Result(Status.SUCCESS, "更新职务年限成功", "");
    }

    /**
     * 根据id获取人员信息
     *
     * @param id
     * @return
     */

    @RequestMapping(method = RequestMethod.GET, value = "/{id}")
    public Person person(@PathVariable int id) {
        Person person = personMapper.selectByPrimaryKey(id);
        return person;
    }


    @PreAuthorize("hasAnyAuthority('ROLE_USER','ROLE_ADMIN')")
    @RequestMapping(method = RequestMethod.GET, value = "/communityPerson")
    public Result communityPerson(HttpServletRequest request, HttpServletResponse response) {
        HttpSession httpSession = request.getSession();
        User user = (User) httpSession.getAttribute("userInfo");
        if (null == user) {
            return new Result(Status.NOUSER, "登录用户已经失效，请重新登录！", null);
        }

        QueryPerson person = new QueryPerson();
        System.out.println(user.getCommunityId());
        person.setCommunityId(user.getCommunityId());
        person.setIsDelete(0);
        List<Person> persons = personMapper.selectSelective(person);
        return new Result(persons, "获取数据成功");
    }

    /**
     * 新建人员信息
     *
     * @param request
     * @param response
     * @return
     */
    @Transactional
    @RequestMapping(method = RequestMethod.POST, value = "/create")
    public EditorResult<Person> create(HttpServletRequest request, HttpServletResponse response) throws Exception {
        Person person = new Person();
        HttpSession httpSession = request.getSession();
        User user = (User) httpSession.getAttribute("userInfo");
        person.setUserId(user.getUserId());
        person.setRegisterTime(new Date());
        EditorResult<Person> personEditorResult = new EditorResult<>();
        List<FieldError> fieldErrorList = new ArrayList<>();
//        house.setHouseId(houseId);
        getPerson(request, "data[0][", person, fieldErrorList);
        if (null == person.getNumber()) {
            person.setNumber(personMapper.getMaxNumber() + 1);
        }

        person.setRegisterTime(new Date());
        if (null == person.getDepartId()) {
            person.setDepartId(1);
        }


        if (fieldErrorList.size() > 0) {
            logger.error("字段格式错误");
            personEditorResult.setFieldErrors(fieldErrorList);
            response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
            return personEditorResult;
        }


        if (personMapper.insertSelective(person) > 0) {
            List<Person> data = new ArrayList<>();
            data.add(personMapper.selectByPrimaryKey(person.getPersonId()));
            personEditorResult.setData(data);

            PersonLog personLog = new PersonLog(person, new Date(), user.getUserId());
            if (personLogMapper.insertSelective(personLog) > 0) {
                logger.info("保存资产日志信息成功");
            } else {
                logger.info("保存资产日志信息失败");
                response.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED);

            }
        } else {
            response.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
        }


        return personEditorResult;

    }

    /**
     * 批量修改人员信息， id以,号分割
     *
     * @param houseIdStr
     * @param request
     * @return
     */

    @Transactional
    @RequestMapping(method = RequestMethod.PUT, value = "/edit")
    public Object edit(@RequestParam("id") String houseIdStr, HttpServletRequest request, HttpServletResponse response) throws Exception {
        HttpSession httpSession = request.getSession();
        User user = (User) httpSession.getAttribute("userInfo");
        String[] arr = houseIdStr.split(",");
        EditorResult<Person> personEditorResult = new EditorResult<>();
        List<Person> data = new ArrayList<>();
        for (int i = 0; i < arr.length; i++) {
            int personId = Integer.valueOf(arr[i]);
            Person person = new Person();
            person.setPersonId(personId);
            List<FieldError> fieldErrorList = new ArrayList<>();
            System.out.println("personId--------" + person.getPersonId());
            person.setUserId(user.getUserId());
            getPerson(request, "data[" + personId + "][", person, fieldErrorList);

            if (fieldErrorList.size() > 0) {
                logger.error("字段格式错误");
                personEditorResult.setFieldErrors(fieldErrorList);
                response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
                return personEditorResult;
            }

            if (personMapper.updateByPrimaryKeySelective(person) > 0) {
                Person p = personMapper.selectByPrimaryKey(personId);
                System.out.println("p--------" + person.getPersonId());
                data.add(p);
                PersonLog personLog = new PersonLog(p, new Date(), user.getUserId());

                if (personLogMapper.insertSelective(personLog) > 0) {
                    logger.info("保存资产日志信息成功");
                } else {
                    logger.info("保存资产日志信息失败");
                    response.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED);

                }


            } else {
                response.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
            }


        }
        personEditorResult.setData(data);
        return personEditorResult;


    }


    /**
     * 人员删除
     * 通过资ID批量删除人员信息， id以,号分割
     *
     * @param personIdStr
     * @param response
     * @return
     */
    @Transactional
    @RequestMapping(method = RequestMethod.DELETE, value = "/remove")
    public Object remove(@RequestParam("id") String personIdStr, HttpServletResponse response) {
        String[] arr = personIdStr.split(",");
        EditorResult<Person> personEditorResult = new EditorResult<>();
        for (int i = 0; i < arr.length; i++) {
            int personId = Integer.valueOf(arr[i]);

            Person person = new Person();
            person.setPersonId(personId);
            person.setIsDelete(1);
            if (personMapper.updateByPrimaryKeySelective(person) > 0) {
                System.out.println("删除" + personId + "成功！");


            } else {
                response.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
            }
        }
        return personEditorResult;


    }

    /**
     * dataTables 表单数据返回
     *
     * @param request
     * @return
     */

    @Transactional
    @RequestMapping(method = RequestMethod.GET, value = "/pageDatatables")
    public DataTablePageUtil<Person> pageDatatables(HttpServletRequest request, Integer userTypeId, QueryPerson person) {
//		HttpSession httpSession = request.getSession();
//		User user = (User) httpSession.getAttribute("userInfo");
//		logger.info("用户信息：" + user.toString());
//		int community_id = user.getCommunity().getCommunityId();
//		person.setCommunityId(community_id);

        List<Community> communities = communityMapper.findCommunitys();
        Options os = new Options();
        List<Option> optionList = new ArrayList<>();
        for (Community community : communities) {

            Option option = new Option();
            option.setLabel(community.getCommunityName());
            option.setValue(community.getCommunityId());
            optionList.add(option);


        }
        os.setCommunityId(optionList);
        List<Depart> departs = departMapper.findDeparts();
        optionList = new ArrayList<>();
        for (Depart depart : departs) {

            Option option = new Option();
            option.setLabel(depart.getDepartName());
            option.setValue(depart.getDepartId());
            optionList.add(option);


        }

        os.setDepartId(optionList);

        List<PositionType> positionTypes = positionTypeMapper.findPositionTypes();
        optionList = new ArrayList<>();
        for (PositionType positionType : positionTypes) {

            Option option = new Option();
            option.setLabel(positionType.getPositionName());
            option.setValue(positionType.getPositionId());
            optionList.add(option);


        }
        os.setPositionId(optionList);


        List<PersonCc> personCcs = personCcMapper.findPersonCcs();
        optionList = new ArrayList<>();
        for (PersonCc personCc : personCcs) {

            Option option = new Option();
            option.setLabel(personCc.getCcName());
            option.setValue(personCc.getCcId());
            optionList.add(option);


        }
        os.setCcId(optionList);

        DataTablePageUtil<Person> dataTable = new DataTablePageUtil<>(request);
        person.setIsDelete(0);
        if (null != userTypeId && userTypeId == 4) {
            person.setLeaveStatus(0);
        }

        PageHelper.startPage(dataTable.getPage_num(), 10);
        List<Person> list = personMapper.selectSelective(person);
        for (Person person1 : list) {
            System.out.println(person1.getSWorkDate());

        }
        PageInfo<Person> pageInfo = new PageInfo<>(list);
        System.out.println(list.size());
        dataTable.setDraw(dataTable.getDraw());
        dataTable.setData(pageInfo.getList());
        dataTable.setOptions(os);
        dataTable.setRecordsTotal((int) pageInfo.getTotal());
        dataTable.setRecordsFiltered(dataTable.getRecordsTotal());
        //返回数据到页面

        return dataTable;

    }


    private void getPerson(HttpServletRequest request, String prefix, Person person, List<FieldError> fieldErrorList) {
        if (null != request.getParameter(prefix + "communityId]") && !request.getParameter(prefix + "communityId]").isEmpty()) {
            person.setCommunityId(Integer.valueOf(request.getParameter(prefix + "communityId]")));


        }
        if (null != request.getParameter(prefix + "departId]") && !request.getParameter(prefix + "departId]").isEmpty()) {
            person.setDepartId(Integer.valueOf(request.getParameter(prefix + "departId]")));


        }
        person.setPersonName(request.getParameter(prefix + "personName]"));
        person.setSex(request.getParameter(prefix + "sex]"));
        try {
            person.setBirthday(DateUtil.StrToDate1(request.getParameter(prefix + "birthday]")));
        } catch (Exception e) {
            logger.error("时间格式不正确，必须为YYYY-MM-DD");
            FieldError fieldError = new FieldError("birthday", "时间格式不正确，必须为YYYY-MM-DD时间格式不正确，必须为YYYY-MM-DD");
            fieldErrorList.add(fieldError);
        }
        if (null != request.getParameter(prefix + "dsznDeadline]")&&request.getParameter(prefix + "isDszn]").toString().equals(1)) {
            try {
                person.setDsznDeadline(DateUtil.StrToDate1(request.getParameter(prefix + "dsznDeadline]")));
            } catch (Exception e) {
                logger.error("时间格式不正确，必须为YYYY-MM-DD");
                FieldError fieldError = new FieldError("dsznDeadline", "时间格式不正确，必须为YYYY-MM-DD时间格式不正确，必须为YYYY-MM-DD");
                fieldErrorList.add(fieldError);
            }
        }

        person.setEducation(request.getParameter(prefix + "education]"));
        if (person.getPersonName().isEmpty()) {
            logger.error("不能为空");
            FieldError fieldError = new FieldError("personName", "不能为空");
            fieldErrorList.add(fieldError);
        }
        person.setPersonPolitica(request.getParameter(prefix + "personPolitica]"));
        if (person.getPersonPolitica().isEmpty()) {
            logger.error("不能为空");
            FieldError fieldError = new FieldError("personPolitica", "不能为空");
            fieldErrorList.add(fieldError);
        }
        person.setNationality(request.getParameter(prefix + "nationality]"));
        try {
            person.setSWorkDate(DateUtil.StrToDate1(request.getParameter(prefix + "sWorkDate]")));
        } catch (Exception e) {
            logger.error("时间格式不正确，必须为YYYY-MM-DD");
            FieldError fieldError = new FieldError("sWorkDate", "时间格式不正确，必须为YYYY-MM-DD时间格式不正确，必须为YYYY-MM-DD");
            fieldErrorList.add(fieldError);
        }
        person.setHouseholdAddr(request.getParameter(prefix + "householdAddr]"));
        if (person.getHouseholdAddr().isEmpty()) {
            logger.error("不能为空");
            FieldError fieldError = new FieldError("householdAddr", "不能为空");
            fieldErrorList.add(fieldError);
        }
        person.setLiveAddr(request.getParameter(prefix + "liveAddr]"));
        if (person.getLiveAddr().isEmpty()) {
            logger.error("不能为空");
            FieldError fieldError = new FieldError("liveAddr", "不能为空");
            fieldErrorList.add(fieldError);
        }
        person.setFamilyPhone(request.getParameter(prefix + "familyPhone]"));
        if (person.getFamilyPhone().isEmpty()) {
            logger.error("不能为空");
            FieldError fieldError = new FieldError("familyPhone", "不能为空");
            fieldErrorList.add(fieldError);
        }
        person.setMobilePhone(request.getParameter(prefix + "mobilePhone]"));
        if (person.getMobilePhone().isEmpty()) {
            logger.error("不能为空");
            FieldError fieldError = new FieldError("mobilePhone", "不能为空");
            fieldErrorList.add(fieldError);
        }
        person.setCardCode(request.getParameter(prefix + "cardCode]"));

        if (person.getCardCode().isEmpty()) {
            logger.error("不能为空");
            FieldError fieldError = new FieldError("cardCode", "不能为空");
            fieldErrorList.add(fieldError);
        }
        person.setIcetuCode(request.getParameter(prefix + "icetuCode]"));

        if (null != request.getParameter(prefix + "number]")) {
            try {
                person.setNumber(Integer.valueOf(request.getParameter(prefix + "number]")));
            } catch (Exception e) {
                logger.error("格式不正确，必须为整形数字");
                FieldError fieldError = new FieldError("number", "格式不正确，必须为整形数字");
                fieldErrorList.add(fieldError);
            }
        }
        try {
            person.setCcId(Integer.valueOf(request.getParameter(prefix + "ccId]")));
        } catch (NumberFormatException e) {
            logger.error("格式不正确，必须为整形数字");
            FieldError fieldError = new FieldError("ccId", "格式不正确，必须为整形数字");
            fieldErrorList.add(fieldError);
        }
        try {
            person.setPositionId(Integer.valueOf(request.getParameter(prefix + "positionId]")));
        } catch (NumberFormatException e) {
            logger.error("格式不正确，必须为整形数字");
            FieldError fieldError = new FieldError("positionId", "格式不正确，必须为整形数字");
            fieldErrorList.add(fieldError);
        }
        try {
            person.setEnlistType(request.getParameter(prefix + "enlistType]"));
        } catch (Exception e) {
            logger.error("必须选择是或者否");
            FieldError fieldError = new FieldError("enlistType", "必须选择是或者否");
            fieldErrorList.add(fieldError);
        }
        try {
            person.setIsIntern(Integer.valueOf(request.getParameter(prefix + "isIntern]")));
        } catch (Exception e) {
            logger.error("必须选择是或者否");
            FieldError fieldError = new FieldError("isIntern", "必须选择是或者否");
            fieldErrorList.add(fieldError);
        }
        try {
            person.setIsDszn(Integer.valueOf(request.getParameter(prefix + "isDszn]")));
        } catch (Exception e) {
            logger.error("必须选择是或者否");
            FieldError fieldError = new FieldError("isDszn", "必须选择是或者否");
            fieldErrorList.add(fieldError);
        }
        try {
            person.setLiveCommunity(request.getParameter(prefix + "liveCommunity]"));
        } catch (Exception e) {
            logger.error("必须选择是或者否");
            FieldError fieldError = new FieldError("liveCommunity", "必须选择是或者否");
            fieldErrorList.add(fieldError);
        }
        try {
            person.setLiveAvenue(request.getParameter(prefix + "liveAvenue]"));
        } catch (Exception e) {
            logger.error("必须选择是或者否");
            FieldError fieldError = new FieldError("liveAvenue", "必须选择是或者否");
            fieldErrorList.add(fieldError);
        }
            /*try {
            person.setRegisterTime(DateUtil.StrToDate1(request.getParameter(prefix + "registerTime]")));
		} catch (Exception e) {
			logger.error("时间格式不正确，必须为YYYY-MM-DD");
			FieldError fieldError =new FieldError("registerTime","时间格式不正确，必须为YYYY-MM-DD时间格式不正确，必须为YYYY-MM-DD");
			fieldErrorList.add(fieldError);
		}*/

        if (null != request.getParameter(prefix + "zwnxbt]") && !request.getParameter(prefix + "zwnxbt]").isEmpty()) {
            try {
                person.setZwnxbt(Double.valueOf(request.getParameter(prefix + "zwnxbt]")));
            } catch (NumberFormatException e) {
                logger.error("格式不正确，必须为数字");
                FieldError fieldError = new FieldError("zwnxbt", "格式不正确，必须为数字");
                fieldErrorList.add(fieldError);
            }
        }else{
            person.setZwnxbt(0.0);
        }
        if (null != request.getParameter(prefix + "pension]") && !request.getParameter(prefix + "pension]").isEmpty()) {

            try {
                person.setPension(Double.valueOf(request.getParameter(prefix + "pension]")));
            } catch (NumberFormatException e) {
                logger.error("格式不正确，必须为数字");
                FieldError fieldError = new FieldError("pension", "格式不正确，必须为数字");
                fieldErrorList.add(fieldError);
            }
        }else{
            person.setPension(0.0);
        }
        if (null != request.getParameter(prefix + "medicare]") && !request.getParameter(prefix + "medicare]").isEmpty()) {

            try {

                person.setMedicare(Double.valueOf(request.getParameter(prefix + "medicare]")));
            } catch(NumberFormatException e){
                logger.error("格式不正确，必须为数字");
                FieldError fieldError = new FieldError("medicare", "格式不正确，必须为数字");
                fieldErrorList.add(fieldError);
            }
        }else{
            person.setMedicare(0.0);
        }
        if (null != request.getParameter(prefix + "unemployment]") && !request.getParameter(prefix + "unemployment]").isEmpty()) {

            try {
                person.setUnemployment(Double.valueOf(request.getParameter(prefix + "unemployment]")));
            } catch (NumberFormatException e) {
                logger.error("格式不正确，必须为数字");
                FieldError fieldError = new FieldError("unemployment", "格式不正确，必须为数字");
                fieldErrorList.add(fieldError);
            }
        }else{
            person.setUnemployment(0.0);
        }
        if (null != request.getParameter(prefix + "providentFund]") && !request.getParameter(prefix + "providentFund]").isEmpty()) {

            try {
                person.setProvidentFund(Double.valueOf(request.getParameter(prefix + "providentFund]")));
            } catch (NumberFormatException e) {
                logger.error("格式不正确，必须为数字");
                FieldError fieldError = new FieldError("providentFund", "格式不正确，必须为数字");
                fieldErrorList.add(fieldError);
            }
        }else{
            person.setProvidentFund(0.0);
        }
        if (null != request.getParameter(prefix + "incomeTax]") && !request.getParameter(prefix + "incomeTax]").isEmpty()) {

            try {
                person.setIncomeTax(Double.valueOf(request.getParameter(prefix + "incomeTax]")));
            } catch (NumberFormatException e) {
                logger.error("格式不正确，必须为数字");
                FieldError fieldError = new FieldError("incomeTax", "格式不正确，必须为数字");
                fieldErrorList.add(fieldError);
            }
        }else{
            person.setIncomeTax(0.0);
        }
        if (null != request.getParameter(prefix + "backPay]") && !request.getParameter(prefix + "backPay]").isEmpty()) {

            try {
                person.setBackPay(Double.valueOf(request.getParameter(prefix + "backPay]")));
            } catch (NumberFormatException e) {
                logger.error("格式不正确，必须为数字");
                FieldError fieldError = new FieldError("backPay", "格式不正确，必须为数字");
                fieldErrorList.add(fieldError);
            }
        }else{
            person.setBackPay(0.0);
        }
        if (null != request.getParameter(prefix + "supPf]") && !request.getParameter(prefix + "supPf]").isEmpty()) {

            try {
                person.setSupPf(Double.valueOf(request.getParameter(prefix + "supPf]")));
            } catch (NumberFormatException e) {
                logger.error("格式不正确，必须为数字");
                FieldError fieldError = new FieldError("supPf", "格式不正确，必须为数字");
                fieldErrorList.add(fieldError);
            }
        }else{
            person.setSupPf(0.0);
        }
        if (null != request.getParameter(prefix + "supI]") && !request.getParameter(prefix + "supI]").isEmpty()) {

            try {
                person.setSupI(Double.valueOf(request.getParameter(prefix + "supI]")));
            } catch (NumberFormatException e) {
                logger.error("格式不正确，必须为数字");
                FieldError fieldError = new FieldError("supI", "格式不正确，必须为数字");
                fieldErrorList.add(fieldError);
            }
        }else{
            person.setSupI(0.0);
        }
        if (null != request.getParameter(prefix + "ccDate]") && !request.getParameter(prefix + "ccDate]").isEmpty()) {
            try {
                person.setCcDate(DateUtil.StrToDate1(request.getParameter(prefix + "ccDate]")));
            } catch (Exception e) {
                logger.error("时间格式不正确，必须为YYYY-MM-DD");
                FieldError fieldError = new FieldError("ccDate", "时间格式不正确，必须为YYYY-MM-DD时间格式不正确，必须为YYYY-MM-DD");
                fieldErrorList.add(fieldError);
            }
        }

    }


}
